package persistence;

import javax.validation.constraints.NotNull;

final public class CostUnit {
	private int id=0;
	private String name;
	@NotNull
	private int number;
	@NotNull
	private LibraryLocation location;
	
	protected CostUnit(){}
	
	protected CostUnit(int id, String name, int number, LibraryLocation location) {
		setId(id);
		setName(name);
		setNumber(number);
		setLocation(location);
	}	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		result = prime * result
				+ ((location == null) ? 0 : location.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + number;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CostUnit other = (CostUnit) obj;
		if (id != other.id)
			return false;
		if (location == null) {
			if (other.location != null)
				return false;
		} else if (!location.equals(other.location))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (number != other.number)
			return false;
		return true;
	}
	
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append(this.getClass().getName()).append(": id=").append(id).append(", number=").append(number).
		append(", location=").append(location);
		
		return builder.toString();
	}

	public int getId() {
		return id;
	}
	public String getName() {
		return name;
	}
	public int getNumber() {
		return number;
	}
	public LibraryLocation getLocation() {
		return location;
	}
	public void setLocation(LibraryLocation location) {
		this.location = location;
	}
	public void setId(int id) {
		this.id = id;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setNumber(int number) {
		this.number = number;
	}	
}
